﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Game.Facade;
using Game.Kernel;
using Game.Utils;
using Game.Entity.Accounts;
using Game.Entity.Treasure;

namespace Game.Card.Menu
{
    public partial class Present : AdminPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            SiteMaster.Menu = 3;
            if(!IsPostBack)
            {
                //获取登录信息
                UserTicketInfo user = userTicket;

                //获取房卡信息
                UserRoomCard card = FacadeManage.aideTreasureFacade.GetUserRoomCard(user.UserID);
                lbRoomCard.Text = card != null ? card.RoomCard.ToString() : "0";

                //获取今日赠送房卡
                lbPresentCard.Text = FacadeManage.aideRecordFacade.GetPresentRoomCard(user.UserID);
            }
        }

        /// <summary>
        /// 确定赠送
        /// </summary>
        protected void btnPresent_Click(object sender, EventArgs e)
        {
            //获取赠送数据
            int gameID = CtrlHelper.GetInt(txtGameID, 0);
            int presentCount = CtrlHelper.GetInt(txtPresentCount,0);
            string password = CtrlHelper.GetText(txtPassword);
            //string descript = CtrlHelper.GetText(txtDescript);

            //数据验证
            if(gameID <= 0)
            {
                ShowInfo("抱歉，赠送对象无效");
                return;
            }
            if(presentCount <= 0)
            {
                ShowInfo("抱歉，赠送房卡数需大于或等于零");
                return;
            }
            if(string.IsNullOrEmpty(password))
            {
                ShowInfo("抱歉，银行密码不能为空");
                return;
            }

            //执行赠送操作
            Message msg = FacadeManage.aideTreasureFacade.PresentRoomCard(userTicket.UserID, TextEncrypt.EncryptPassword(password), presentCount, gameID, GameRequest.GetUserIP(), "");
            if(msg.Success)
            {
                Response.Redirect("/Menu/PresentSuccess.aspx");
            }
            else
            {
                txtGameID.Text = "";
                ShowInfo(msg.Content);
            }
        }
    }
}